package com.tupu.service.impl.dispatch;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tupu.entity.dispatch.SignalfrequencyLevel;
import com.tupu.service.dispatch.SignalfrequencyLevelService;
import com.tupu.mapper.dispatch.SignalfrequencyLevelMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
* @author 15702
* @description 针对表【tb_signalfrequency_level】的数据库操作Service实现
* @createDate 2023-11-15 14:48:32
*/
@Service
public class SignalfrequencyLevelServiceImpl extends ServiceImpl<SignalfrequencyLevelMapper, SignalfrequencyLevel>
    implements SignalfrequencyLevelService{
    ConcurrentHashMap<String, List<SignalfrequencyLevel>> stringSignalfrequencyLevelLinkedHashMap = new ConcurrentHashMap<>();

    @Override
    public List<SignalfrequencyLevel> getLevelByText(String c0420AlmText) {
        List<SignalfrequencyLevel> signalfrequencyLevels = stringSignalfrequencyLevelLinkedHashMap.get(c0420AlmText);
        if (signalfrequencyLevels == null) {
            signalfrequencyLevels = this.baseMapper.getLevelByText(c0420AlmText);
            stringSignalfrequencyLevelLinkedHashMap.put(c0420AlmText, signalfrequencyLevels);
        }
        return signalfrequencyLevels;
    }

    @Override
    public List<SignalfrequencyLevel> getLevelByTextNoCache(String c0420AlmText) {
        stringSignalfrequencyLevelLinkedHashMap.clear();
        return this.baseMapper.getLevelByText(c0420AlmText);
    }

    @Override
    public Page<SignalfrequencyLevel> page(String signalType, String importantType, String solveWay, Long page, Long size) {
        QueryWrapper<SignalfrequencyLevel> queryWrapper = new QueryWrapper<>();
        Page<SignalfrequencyLevel> info = new Page<>(page, size);
        if (StringUtils.isNotEmpty(signalType)) {
            queryWrapper.eq("signal_type", signalType);
        }
        if (StringUtils.isNotEmpty(solveWay)) {
            if (solveWay.equals("延时告警")) {
                queryWrapper.eq("delay_alarm", 1);

            } else if (solveWay.equals("抑制告警")) {
                queryWrapper.eq("suppression_alarm", 1);

            }

        }

        baseMapper.selectPage(info, queryWrapper);
        return info;
    }
}




